package com.cn.zpark.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Date;

/**
 * @PackageName: com.cn.zpark.servlet
 * @ClassName: ServletDemo
 * @Description:
 * @author: RZS
 * @date: 2022/4/15  9:35
 */
@WebServlet("/sd2.do")
public class ServletDemo02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /**
         * 绑定数据到session域中
         * 修改绑定数据
         * 移除绑定数据
         */
        // 获取session对象
        HttpSession session = request.getSession();

        // 绑定数据
        System.out.println("绑定数据");
        session.setAttribute("zpark", "中关村软件园");

        // 修改绑定数据
        System.out.println("修改绑定数据");
        session.setAttribute("zpark", new Date());

        // 移除绑定数据
        System.out.println("移除绑定数据");
        session.removeAttribute("zpark");


    }
}
